package com.zyong.design.pattern.flyweight.case2;

import java.util.HashMap;
import java.util.Map;

/**
 * 享元工厂
 * @program: zyong-design-pattern
 * @ClassName: GameFactory
 * @author: zyong
 * @create: 2024-04-06 11:01
 */
public class GameFactory {
    private static Map<TankType, Tank> tanks = new HashMap<>();

    public static Tank getTank(TankType tankType) {
        Tank tank = tanks.get(tankType);

        if (tank == null) {
            System.out.println("【新创建】一个坦克, 颜色为: " + tankType.getColor() + ", 速度为: " + tankType.getSpeed());

            tank = new Tank(tankType);
            tanks.put(tankType, tank);

            return tank;
        }

        System.out.println("【获取】一个坦克, 颜色为: " + tankType.getColor() + ", 速度为: " + tankType.getSpeed());

        return tank;
    }

    public static Tank getTankWithOutFlyWeight(TankType tankType) {
        return new Tank(tankType);
    }

    public static Home getHome(String team) {
        if (team.equals("红队")) {
            return new Home("1", "红队基地");
        }

        return new Home("2", "蓝队基地");
    }
}

